
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


///滑动更换页面
void main()=>runApp(pages());

class pages extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      home: new s(),

      theme: ThemeData(
          primaryColor: Colors.white
      ),
      darkTheme: ThemeData(
          primaryColor: Colors.black
      ),
      themeMode: ThemeMode.dark,
    );
  }
}


class s extends StatefulWidget {
  const s({Key key}) : super(key: key);

  @override
  _TState createState() => _TState();
}

class _TState extends State<s> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: null,
        automaticallyImplyLeading: false,
        title: Text("widget.title"),
      ),
      body: PageView(
        scrollDirection: Axis.horizontal,
        reverse: false,
        controller: PageController(
          initialPage: 0,
          viewportFraction: 1,
          keepPage: true,
        ),
        physics:BouncingScrollPhysics(),
        pageSnapping: true,
        onPageChanged: (index) {
          //监听事件
          print('index=====$index');
        },
        children: <Widget>[
          Container(
            color: Colors.tealAccent,
            child: Center(
              child: Text(
                '第1页',
                style: TextStyle(color: Colors.black, fontSize: 18.0),
              ),
            ),
          ),
          Container(
            color: Colors.greenAccent,
            child: Center(
              child: Text(
                '第2页',
                style: TextStyle(color: Colors.black, fontSize: 20.0),
              ),
            ),
          ),
          Container(
            color: Colors.deepOrange,
            child: Center(
              child: Text(
                '第3页',
                style: TextStyle(color: Colors.black, fontSize: 20.0),
              ),
            ),
          )
        ],
      ),
    );
  }
}
